package game.adm.struts.action;

import game.adm.controller.PayInitController;
import game.adm.dao.dto.PayDTO;
import game.adm.struts.form.PayForm;
import game.adm.viewhelper.PayViewHelper;
import game.web.base.Constants;
import game.web.base.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import projectx.util.ClassUtil;
import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXForm;
import projectx.web.base.ProjectXSecurityAction;
import projectx.web.base.UserContext;
import projectx.web.base.navi.Function;

public class PayInitAction extends ProjectXSecurityAction {

	@Override
	protected boolean isPostMethodOnly() {
		return false;
	}

	@Override
	protected ActionForward execute(User user, Function function,
			ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		UserContext uc = getUc();
		PayForm payForm = (PayForm) form;
		PayInitController.execute(uc, (ProjectXForm) form);
		PayDTO dto = (PayDTO)uc.get(Constants.ADM_PAY_RECORD);
		if(dto==null)
			dto = new PayDTO();
		PayViewHelper viewHelper = new PayViewHelper();
		ClassUtil.copyData(dto, viewHelper);
		viewHelper.setUser(user);
		request.setAttribute(ConstantsProjectX.VIEW_HELPER, viewHelper);
		debugEnd();
		return findForward(mapping, forwardSuccess);
	}
	
}
